<?php
require('qs_connection.php');
require('qs_functions.php');
@session_start();
$err_string = "";
//Check security login 
$pagesecure_level = 7;
if (strtoupper(qsrequest("logout"))=="Y") {
    $_SESSION["UserLevel"] = 0;
    $_SESSION["Logon"] = "FALSE";
    $_SESSION["UserLogon"] = "";
    $_SESSION["RedirectURL"] = qssession("firstredirecturl");
    header ("Location: ./global_group_login.php");
    exit();
}
if (qssession("Logon") != "TRUE") {
    $_SESSION["RedirectURL"] = "./" . rawurlencode("wild_foods_delete").".php?" . qsservervars("QUERY_STRING");
    header ("Location: ./global_group_login.php");
    exit();
}
if (qssession("UserLevel") == "") {
    $_SESSION["UserLevel"] = 0;
}
if (qssession("UserLevel") < $pagesecure_level) {
    $_SESSION["Logon"] = "FALSE";
    $_SESSION["RedirectURL"] = "./" . rawurlencode("wild_foods_delete").".php?" . qsservervars("QUERY_STRING");
    include_once('global_group_login.php');
    exit();
}

$quotechar = "`";
$quotedate = "'";
$sql = "";
$sql_ext = "";
$fields = array();
$fields[0] = "tblincomesourceswf.ProjectID";
$fields[1] = "tblincomesourceswf.IncomeSourceIDWF";
$fields[2] = "tblincomesourceswf.Unit";
$fields[3] = "tblincomesourceswf.KcalsUnit";
$fields[4] = "tblincomesourceswf.PriceUnit";
$fields[5] = "tblincomesourceswf.Newprice";
$fields[6] = "tblincomesourceswf.ModPercent";
$fields = array();
$fields[0] = "tblincomesourceswf.ProjectID";
$fields[1] = "tblincomesourceswf.IncomeSourceIDWF";
$fields[2] = "tblincomesourceswf.Unit";
$fields[3] = "tblincomesourceswf.KcalsUnit";
$fields[4] = "tblincomesourceswf.PriceUnit";
$fields[5] = "tblincomesourceswf.Newprice";
$fields[6] = "tblincomesourceswf.ModPercent";

$fieldcons = array();
$fieldcons[0] = "tblincomesourceswf.ProjectID";
$fieldcons[1] = "tblincomesourceswf.IncomeSourceIDWF";
$fieldcons[2] = "tblincomesourceswf.Unit";
$fieldcons[3] = "tblincomesourceswf.KcalsUnit";
$fieldcons[4] = "tblincomesourceswf.PriceUnit";
$fieldcons[5] = "tblincomesourceswf.Newprice";
$fieldcons[6] = "tblincomesourceswf.ModPercent";

$sql .= " Select\n";
    $sql .= "     tblincomesourceswf.`ProjectID`,\n";
    $sql .= "     tblincomesourceswf.`IncomeSourceIDWF`,\n";
    $sql .= "     tblincomesourceswf.`Unit`,\n";
    $sql .= "     tblincomesourceswf.`KcalsUnit`,\n";
    $sql .= "     tblincomesourceswf.`PriceUnit`,\n";
    $sql .= "     tblincomesourceswf.`Newprice`,\n";
    $sql .= "     tblincomesourceswf.`ModPercent`\n";
    $sql .= " From\n";
    $sql .= "     tblincomesourceswf   tblincomesourceswf\n";

if (strpos(strtoupper($sql), " WHERE ")) {
   $sqltemp = $sql . " AND (1=0) ";
}else{
   $sqltemp = $sql . " Where (1=0) ";
}
$result = mysql_query($sqltemp . " " . $sql_ext . " limit 0,1")
          or die("Invalid query");
$qry_string = "";
$value_sql = "";
$currentrow_sql = "";
$hidden_tag = "";
$hiddenrow_tag = "";
$i = 0;
while ($i < mysql_num_fields($result)) {
    $meta = mysql_fetch_field($result);
    $field_name = $meta->name;
    $field_type = $meta->type;
    $type_field = "";
    $type_field = returntype($field_type);
    $quotedata = "";
    switch ($type_field) {
      case "type_datetime": $quotedata = $quotedate; break;
      case "type_string": $quotedata = "'"; break;
      case "type_integer": $quotedata = ""; break;
      case "type_unknown": $quotedata = "'"; break;
      default: $quotedata = "'";
    } 
    if (qsrequest("currentrow_fd" .$i) != "") {
        if ($currentrow_sql == "") {
            $currentrow_sql  = $fields[$i] . " = " . $quotedata . qsrequest("currentrow_fd" . $i) . $quotedata . "";
        } else {
            $currentrow_sql .= " and " . $fields[$i] . " = " . $quotedata . qsrequest("currentrow_fd" . $i) . $quotedata . "";
        }
        $hiddenrow_tag .= "<input type=\"hidden\" name=\"currentrow_fd" . $i . "\" value=\"" . qsrequest("currentrow_fd" . $i) . "\">\n";
    }
    $i++;
}
if (isset($_POST["act"])) {
    $sql  = "";
    $sql  = "delete from " . $quotechar. mysql_field_table($result,0) . $quotechar;
    $sql .= " where ";
    $sql .= qsreplace_backslashes(stripslashes($currentrow_sql));
#----get submit url page----
    $submiturl = "./wild_foods.php?";
    if ($result > 0) {mysql_free_result($result);}
    if ($err_string == "") {
    if (!$result = @mysql_query($sql)){
        $err_string .= "<strong>Error:</strong>while updating<br>" . mysql_error();
    }
    if ($err_string == "") {
        if ($qry_string != "") {
            $URL= $submiturl . "&" . $qry_string;
        } else {
            $URL= $submiturl;
        }
            header ("Location: $URL");
            exit;
        }
    }
}
else {
    if ($result > 0) {mysql_free_result($result);}
    $sql = "";
$sql .= " Select\n";
    $sql .= "     tblincomesourceswf.`ProjectID`,\n";
    $sql .= "     tblincomesourceswf.`IncomeSourceIDWF`,\n";
    $sql .= "     tblincomesourceswf.`Unit`,\n";
    $sql .= "     tblincomesourceswf.`KcalsUnit`,\n";
    $sql .= "     tblincomesourceswf.`PriceUnit`,\n";
    $sql .= "     tblincomesourceswf.`Newprice`,\n";
    $sql .= "     tblincomesourceswf.`ModPercent`\n";
    $sql .= " From\n";
    $sql .= "     tblincomesourceswf   tblincomesourceswf\n";
  if ($currentrow_sql != "") {
    $sql .= " where ".$currentrow_sql ;
  }
    $result =  mysql_query($sql) or die("Invalid query");
    $row = mysql_fetch_array($result);
}
?>
<HTML>
<HEAD>
<Title>Delete Wild Foods</Title>
<link rel="stylesheet" type="text/css" href="wild_foods_delete.css">
<meta http-equiv="Content-Type" content="text/html; utf-8">
<meta name="generator" content="dbQwikSite Ecommerce">
</HEAD>
<BODY><script language="javascript" src="./js/qs_menu.js"></script>
<CENTER>
<p align="left"><img style="left: 10px; top: 15px" alt="efd" hspace="0" src="http://www.evidencefordevelopment.com/templates/247extender_b/images/efd_100x65.png" align="baseline" border="0" /></p><CENTER>
<center><strong><font size="5">
Delete Wild Foods
</font></strong></center><br>

<A NAME=top></A>
<Form name="qs_delete_form" method="post" action="./wild_foods_delete.php">
<?php
print $hidden_tag;
print $hiddenrow_tag;
?>
<Table Border="0" Cellpadding="2" Cellspacing="1" BgColor="#10783F">

<?php
$css_class = "\"TrOdd\"";
?>
<tr>
<td colspan="2" class="ThRows">Delete Wild Foods</td>
</tr>
<tr>
<td class="ThRows">Project ID</td>
<?php
$itemvalue = "" . number_format($row[0],0,".",",") . "";
if ($itemvalue == "") {
    $itemvalue = "&nbsp;";
}

    $cellvalue =  $itemvalue;
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    }
    print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="ThRows">Income Source IDWF</td>
<?php
$itemvalue = "" . number_format($row[1],0,".",",") . "";
if ($itemvalue == "") {
    $itemvalue = "&nbsp;";
}

    $cellvalue =  $itemvalue;
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    }
    print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="ThRows">Unit</td>
<?php
$itemvalue = "" . $row[2] . "";
if ($itemvalue == "") {
    $itemvalue = "&nbsp;";
}

    $cellvalue =  $itemvalue;
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    }
    print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="ThRows">Kcals Unit</td>
<?php
$itemvalue = "" . number_format($row[3],2,".",",") . "";
if ($itemvalue == "") {
    $itemvalue = "&nbsp;";
}

    $cellvalue =  $itemvalue;
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    }
    print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="ThRows">Price Unit</td>
<?php
$itemvalue = "" . number_format($row[4],2,".",",") . "";
if ($itemvalue == "") {
    $itemvalue = "&nbsp;";
}

    $cellvalue =  $itemvalue;
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    }
    print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="ThRows">Newprice</td>
<?php
$itemvalue = "" . number_format($row[5],2,".",",") . "";
if ($itemvalue == "") {
    $itemvalue = "&nbsp;";
}

    $cellvalue =  $itemvalue;
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    }
    print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="ThRows">Mod Percent</td>
<?php
$itemvalue = "" . number_format($row[6],0,".",",") . "";
if ($itemvalue == "") {
    $itemvalue = "&nbsp;";
}

    $cellvalue =  $itemvalue;
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    }
    print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<?php
#----get back url page----
  $backurl = "./wild_foods.php?";
?>
<tr>
<td class="ThRows">&nbsp;</td>
<td class="TrOdd" align=Default>
<input type="hidden" name="act" value="n">
<input type="button" name="QS_Back" value="Back" OnClick="javascript:window.location='<?php print $backurl; ?>'">&nbsp;&nbsp;
<input type="submit" name="QS_Submit" value="Delete">&nbsp;&nbsp;
</td>
</tr>
</Table><br>
</Form>
<?php
if ($result > 0) {mysql_free_result($result);}
if ($link > 0) {mysql_close($link);}
?>
<A NAME=bottom></A>
<div align="center"><a href="./project_setup.php" target="Back to Project Setup">Back to Project Setup</a></div>
</CENTER>

</BODY>
</HTML>
